package com.tricode.jasper.reports;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.view.JasperViewer;

public class TheMain {
	
	public static void main(String[] args) throws Exception {
		TheMain m = new TheMain();
		m.meth();
	}
	
	private void meth() throws Exception {
		Collection<BeanForDataSource> beanCollection = new ArrayList<BeanForDataSource>();
		beanCollection.add(new BeanForDataSource(1l, "name", "nameType", new Date(), new Date(), 12.5, 10, 125d));
		JRBeanCollectionDataSource beanDataSource = new JRBeanCollectionDataSource(beanCollection);
		InputStream is = this.getClass().getClassLoader().getResourceAsStream("Untitled_report_1.jasper");
		JasperPrint print = JasperFillManager.fillReport(is, null, beanDataSource);
		JasperViewer.viewReport(print);
//		byte[] i = JasperRunManager.runReportToPdf(is, null, beanDataSource);
//		Thread.sleep(5000);
//		File f = new File("D:\\pdf.pdf");
//		if (!f.exists()) f.createNewFile();
//		FileOutputStream fos = new FileOutputStream(f);
//		fos.write(i);
	}

}
